﻿using System.Collections.ObjectModel;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Messaging;
using TeacherLeftHand.DataAccess;
using TeacherLeftHand.Util;

namespace TeacherLeftHand.ViewModel
{
    public class MainWindowViewModel : ViewModelBase
    {
        public MainWindowViewModel()
        {
            _subjectList = new ObservableCollection<string>(_kiAccessor.GetSubjectList());
            Messenger.Default.Register<bool>(this,"IsMainEnabled", (value) => IsMainEnabled = value);
        }

        #region properties
        private KnowledgeItemAccessor _kiAccessor = new KnowledgeItemAccessor();
        #endregion

        /// <summary>
        /// The <see cref="IsMainEnabled" /> property's name.
        /// </summary>
        public const string IsMainEnabledPropertyName = "IsMainEnabled";

        private bool _isMainEnabled = true;

        /// <summary>
        /// Gets the IsMainEnabled property.
        /// TODO Update documentation:
        /// Changes to that property's value raise the PropertyChanged event. 
        /// This property's value is broadcasted by the Messenger's default instance when it changes.
        /// </summary>
        public bool IsMainEnabled
        {
            get
            {
                return _isMainEnabled;
            }

            set
            {
                if (_isMainEnabled == value)
                {
                    return;
                }

                _isMainEnabled = value;

                // Update bindings, no broadcast
                RaisePropertyChanged("IsMainEnabled");
            }
        }

        public ObservableCollection<int> ClassLevelList
        {
            get { return DataHelper.ClassLevelList; }
        }

        /// <summary>
        /// The <see cref="SubjectList" /> property's name.
        /// </summary>
        public const string SubjectListPropertyName = "SubjectList";

        private ObservableCollection<string> _subjectList = new ObservableCollection<string>();

        /// <summary>
        /// Gets the SubjectList property.
        /// TODO Update documentation:
        /// Changes to that property's value raise the PropertyChanged event. 
        /// This property's value is broadcasted by the Messenger's default instance when it changes.
        /// </summary>
        public ObservableCollection<string> SubjectList
        {
            get
            {
                return _subjectList;
            }

            set
            {
                if (_subjectList == value)
                {
                    return;
                }
                _subjectList = value;

                // Update bindings, no broadcast
                RaisePropertyChanged(SubjectListPropertyName);

            }
        }

    }
}
